package com.mio.web.service.log;

import java.util.List;
import java.util.UUID;

import org.durcframework.core.UserContext;
import org.durcframework.core.expression.ExpressionQuery;
import org.durcframework.core.service.CrudService;
import org.springframework.stereotype.Service;

import com.mio.web.dao.log.SysLogDao;
import com.mio.web.entity.log.SysLog;
import com.mio.web.entity.user.User;

@Service
public class SysLogService extends CrudService<SysLog, SysLogDao> {
	public void saveLog(SysLog sysLog) {
		User user = UserContext.getInstance().getUser();
		sysLog.setUserId(user == null ? 0 : user.getId());
		sysLog.setUuid(UUID.randomUUID().toString().replaceAll("-", ""));
		this.getDao().save(sysLog);
	}

	/**
	 * 获取已经访问过该网页的人数
	 * 
	 * @return
	 */
	public long getVisitNumber() {
		ExpressionQuery query = new ExpressionQuery();
		return getDao().findTotalCount(query);
	}

	public boolean isExsist(String remoteAddr, String createdTime) {
		List<SysLog> list = getDao().isExsist(remoteAddr,createdTime);
		if(list!=null && list.size()>0){
			return true;
		}
		return false;
	}
}